package com.iyundao.io.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.iyundao.io.Service.SignInService;
import com.iyundao.io.model.SignIn;
import com.iyundao.io.tools.ResponseData;
import com.iyundao.io.tools.SignInBatch;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/signin")
public class SignInController {

    @Autowired
    private SignInService signInService;

    @ApiOperation(value="集体签到", notes="集体签到")
    @RequestMapping(value = "/batchsignin", produces = {"application/json;charset=UTF-8"})
    @CrossOrigin
    public ResponseData batchSignIn(@RequestBody JSONObject parmas){
        SignInBatch signInBatch = JSON.toJavaObject(parmas, SignInBatch.class);
        Integer[] list = signInBatch.getList();
        Integer activityid = signInBatch.getActivityid();
        return signInService.batchSignIn(list, activityid);
    }

    @ApiOperation(value="个人签到", notes="个人签到")
    @RequestMapping(value = "/addsignin", produces = {"application/json;charset=UTF-8"})
    @CrossOrigin
    public ResponseData signIn(@RequestBody JSONObject parmas){
        SignIn signIn = JSON.toJavaObject(parmas, SignIn.class);
        return signInService.signIn(signIn);
    }
}
